home *** CD-ROM | disk | FTP | other *** search
- // xref.cpp : Defines the initialization routines for the DLL.
- //
- #include "stdafx.h"
- #include <io.h>
- #include "xref.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- //
- // Note!
- //
- // If this DLL is dynamically linked against the MFC
- // DLLs, any functions exported from this DLL which
- // call into MFC must have the AFX_MANAGE_STATE macro
- // added at the very beginning of the function.
- //
- // For example:
- //
- // extern "C" BOOL PASCAL EXPORT ExportedFunction()
- // {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // // normal function body here
- // }
- //
- // It is very important that this macro appear in each
- // function, prior to any calls into MFC. This means that
- // it must appear as the first statement within the
- // function, even before any object variable declarations
- // as their constructors may generate calls into the MFC
- // DLL.
- //
- // Please see MFC Technical Notes 33 and 58 for additional
- // details.
- //
-
- /////////////////////////////////////////////////////////////////////////////
- // CXrefApp
-
- BEGIN_MESSAGE_MAP(CXrefApp, CWinApp)
- //{{AFX_MSG_MAP(CXrefApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CXrefApp construction
-
- CXrefApp::CXrefApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CXrefApp object
-
- CXrefApp theApp;
-
- /*
- This is provided in case you need to do some initialization.
- It will be called when Myriad starts up.
-
- return TRUE if you startup successfully.
- returning FALSE will cause Myriad to unload your xref.dll
- and proceed without you.
- */
-
- BOOL CXrefApp::Init(void)
- {
- BOOL ret = FALSE;
- char filename[MAX_PATH];
-
- // get filename for xref list
- if( GetModuleFileName( m_hInstance, filename, MAX_PATH) > 0 )
- {
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
-
- _splitpath( filename, drive, dir, NULL, NULL);
- _makepath( filename, drive, dir, "srchpath", "txt" );
-
- ret = LoadSearchPaths(filename);
- }
-
- return ret;
- }
-
- /*
- LocalFile = Path and filename of the file wanting the xref.
- Ignore this parameter if the xref is an .ini
- file or a .dat file. Those files have no parent file.
- This string may be empty or garbage in those cases.
- Myriad uses this function for more than just xrefs.
- It gets called for ini files, library dat files and font files too.
- You may want to ignore (return FALSE) if all you care
- about are externally refrenced dwg files and the xref does
- not end in a ".dwg" extension.
-
- xref = Externally refrenced file to find. The exact string
- specified in the parent file, so it may be a full path,
- or just a filename. May be any of the following types
- of files: .ini, .dat, .dwg, .shx and .ttf
-
- Answer = character buffer to write your answer to.
- Supply a full path to the file you want us to use.
-
- Answersize = size, in bytes, of the character buffer pointed to by Answer.
-
- Return TRUE, if you want us to use the file you write to the Answer
- buffer. Otherwise, return FALSE and Myriad will search for the xref
- the way it normally does.
- */
- BOOL CXrefApp::GetXref(LPCSTR LocalFile, LPCSTR xref, char *Answer, int Answersize)
- {
- BOOL ret = FALSE;
-
- if(m_SearchPaths.GetCount())
- {
- CString buffer;
- char filename[MAX_PATH];
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
-
- POSITION currentpos = m_SearchPaths.GetHeadPosition();
-
- while(currentpos)
- {
- buffer = m_SearchPaths.GetNext( currentpos );
- if(buffer.GetLength() > 0)
- {
- _splitpath( buffer, drive, dir, NULL, NULL);
- _makepath( filename, drive, dir, xref, NULL);
-
- if(_access( filename, 04 ) != -1)
- {
- strncpy(Answer, filename, Answersize);
- ret = TRUE;
- break;
- }
- }
- }
- }
-
- return ret;
- }
-
- /*
- This is provided in case you need to clean up.
- It will be called when Myriad shuts down.
- */
-
- void CXrefApp::DeInit(void)
- {
- }
-
- BOOL CXrefApp::LoadSearchPaths(LPCSTR filename)
- {
- BOOL ret = FALSE;
-
- if(_access( filename, 04 ) != -1)
- {
- CString buffer;
- CStdioFile listfile( filename, CFile::modeRead );
-
- while(listfile.ReadString(buffer))
- {
- if(buffer.GetLength() > 0 )
- {
- m_SearchPaths.AddTail(buffer);
- }
- }
-
- if(m_SearchPaths.GetCount())
- {
- ret = TRUE;
- }
- }
-
- return ret;
- }